﻿using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Nest;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ES.Client.Demo
{
    /// <summary>
    /// 联系人
    /// </summary>
    [ElasticsearchType(Name = "Contacts.Contact", IdProperty = "")]
    public class Contact
    {
        [Nest.Number(Name = "EventSubType1111")]
        public EventSubType SubType { get; set; }

        /// <summary>
        /// 业务主键
        /// </summary>
        public long ContactId { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        public string RealName { get; set; }

        /// <summary>
        /// 称谓
        /// </summary>
        public string Appellation { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        [Nest.String(Index = FieldIndexOption.NotAnalyzed, Name = "MobileTest")]
        public string Mobile { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// 职位
        /// </summary>
        public string PosStatusEx { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        [Nest.String(Name = "Addr")]
        public string Address { get; set; }

        /// <summary>
        /// 固话
        /// </summary>
        public string Phone { get; set; }

        /// <summary>
        /// 身份证
        /// </summary>
        public string IDCard { get; set; }

        /// <summary>
        /// 微信
        /// </summary>
        public string WeiXin { get; set; }
        /// <summary>
        /// 兼容单会不报错-性别
        /// </summary>
        public string SexEx { get; set; }
        /// <summary>
        /// 兼容单会不报错-微博
        /// </summary>
        public string Weibo { get; set; }
        /// <summary>
        /// 兼容单会不报错-备注
        /// </summary>
        public string Memo { get; set; }

        /// <summary>
        /// 生日
        /// </summary>
        [Nest.Date(Name = "BirthDay", Format = "yyyy-MM-dd'T'HH:mm:ss.SSS'+'Z||yyyy-MM-dd'T'HH:mm:ss||strict_date_optional_time", IgnoreMalformed = true)]
        public DateTime? BirthDay { get; set; }
        /// <summary>
        /// 自定义字段
        /// </summary>
        public Dictionary<string, string> ExtraFields { get; set; }

        /// <summary>
        /// ES反序列化时使用此字段
        /// JSON反序列化时使用此字段
        /// 新增和修改数据保存MongoDB时忽略此字段
        /// </summary>
        [BsonIgnore]
        [JsonProperty("ExtraFieldsForES")]
        [Nest.Object(Name = "ExtraFieldsForES")]
        public Dictionary<string, object> ExtraFieldsForES { get; set; }

        /// <summary>
        /// 此字段用于新增和修改数据保存MongoDB时使用
        /// mongo-connector会根据此字段把变更部分同步到ES
        /// ES反序列化时忽略此字段
        /// JSON反序列化时忽略此字段
        /// 此字段使用BsonDocument是为了提高数据精度
        /// </summary>
        [JsonIgnore]
        [Nest.Object(Ignore = true)]
        [BsonElement("ExtraFieldsForES")]
        public BsonDocument ExtraFieldsForMongo { get; set; }

        /// <summary>
        /// QQ 
        /// </summary>
        public string QQ { get; set; }

        /// <summary>
        /// 公司
        /// </summary>
        public string Company { get; set; }

        public long CompanyId { get; set; }

        /// <summary>
        /// 传真
        /// </summary>
        public string Fax { get; set; }

        public string CountryEx { get; set; }
        /// <summary>
        /// 公司网址
        /// </summary>
        public string CompanyWebsite { get; set; }

        /// <summary>
        /// 当前会员对应的字段值历史ID
        /// </summary>
        public long CurrentFieldValueGroupId { get; set; }

        /// <summary>
        /// 会员类型--
        /// </summary>
        [Obsolete]
        public long LevelId { get; set; }

        /// <summary>
        /// 类型Rank值
        /// </summary>
        [Obsolete]
        public int LevelRank { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string LevelName { get; set; }

        /// <summary>
        /// 会员分组
        /// </summary>
        public List<long> GroupIds { get; set; }

        /// <summary>
        /// 分组一,分组二
        /// </summary>
        public string GroupNames { get; set; }

        /// <summary>
        /// 是否被加入黑名单
        /// </summary>
        public bool IsInBlackList { get; set; }

        /// <summary>
        /// 消费次数
        /// </summary>
        public int ConsumptionCount { get; set; }

        /// <summary>
        /// 消费金额
        /// </summary>
        public double ConsumptionAmount { get; set; }

        /// <summary>
        ///交易关闭数量
        /// </summary>
        public int TradingCloseNumber { get; set; }

        /// <summary>
        /// 最后消费时间段
        /// </summary>
        [Nest.Date(Name = "LastConsumedAtFrom", Format = "yyyy-MM-dd'T'HH:mm:ss.SSS'+'Z||yyyy-MM-dd'T'HH:mm:ss||strict_date_optional_time", IgnoreMalformed = true)]
        public DateTime LastConsumedAtFrom { get; set; }



        /// <summary>
        /// 最后消费时间段
        /// </summary>
        [Nest.Date(Name = "LastConsumedAtTo", Format = "yyyy-MM-dd'T'HH:mm:ss.SSS'+'Z||yyyy-MM-dd'T'HH:mm:ss||strict_date_optional_time", IgnoreMalformed = true)]
        public DateTime LastConsumedAtTo { get; set; }



        /// <summary>
        ///  上次消费时间
        /// </summary>
        [Nest.Date(Name = "LastConsumedAt", Format = "yyyy-MM-dd'T'HH:mm:ss.SSS'+'Z||yyyy-MM-dd'T'HH:mm:ss||strict_date_optional_time", IgnoreMalformed = true)]
        public DateTime LastConsumedAt { get; set; }


        [Nest.Date(Name = "ExpiredAt", Format = "yyyy-MM-dd'T'HH:mm:ss.SSS'+'Z||yyyy-MM-dd'T'HH:mm:ss||strict_date_optional_time", IgnoreMalformed = true)]
        public DateTime ExpiredAt { get; set; }



        /// <summary>
        /// 省
        /// </summary>
        public string Province { get; set; }

        /// <summary>
        /// 市
        /// </summary>
        public string City { get; set; }

        /// <summary>
        /// 标签
        /// </summary>
        public List<string> Tags { get; set; }

        /// <summary>
        /// 标签设置项目
        /// </summary>
        public List<long> TagSettingIds { get; set; }

        /// <summary>
        /// 标签
        /// </summary>
        public string TagsStr { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public List<string> RemarkStates { get; set; }

        /// <summary>
        /// 累计充值金额
        /// </summary>
        public double RechargeAmount { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string RemarkStateSelect { get; set; }

        /// <summary>
        /// 导入选项的Id
        /// </summary>
        public long ImportResultId { get; set; }
        /// <summary>
        /// 推荐人Id
        /// </summary>
        public long PromoterId { get; set; }
        /// <summary>
        /// 推荐人姓名
        /// </summary>
        public string PromoterName { get; set; }
        /// <summary>
        /// 推荐人手机号
        /// </summary>
        public string PromoterMobile { get; set; }

        ///// <summary>
        ///// 报名活动次数
        ///// </summary>
        //public int JoinEventCount { get; set; }
        ///// <summary>
        ///// 报名活动集合。
        ///// </summary>
        //public List<long> JoinEventList { get; set; }
        ///// <summary>
        ///// 签到活动次数
        ///// </summary>
        //public int SignInEventCount { get; set; }
        ///// <summary>
        ///// 签到活动集合
        ///// </summary>
        //public List<long> SignInEventList { get; set; }
        /// <summary>
        /// 联系人初始化
        /// </summary>
        public Contact()
        {
            GroupIds = new List<long>();
            ExtraFields = new Dictionary<string, string>();
        }
        /// <summary>
        /// 积分
        /// </summary>
        public int Integral { get; set; }


        /// <summary>
        /// 参加活动次数
        /// </summary>
        public int InActivitieNumber { get; set; }

        /// <summary>
        /// 已经签到次数
        /// </summary>
        public int SignedInNumber { get; set; }

        /// <summary>
        /// 未签到次数
        /// </summary>
        public int NotSignInNumber { get; set; }


        /// <summary>
        /// 到场率：已签到次数/参加活动总次数
        /// </summary>
        public double AttendanceRate { get; set; }

        /// <summary>
        /// 到场率
        /// </summary>
        public string DisplayAttendanceRate
        {
            get
            {
                if (Math.Abs(AttendanceRate) <= 0)
                {
                    return "0";
                }
                else
                {
                    return (AttendanceRate * 100).ToString("f2") + "%";
                }
            }
        }

        /// <summary>
        /// 缺席率：未签到次数/参加活动总次数
        /// </summary>
        public double AbsenceRate { get; set; }
        /// <summary>
        /// 到场率
        /// </summary>
        public string DisplayAbsenceRate
        {
            get
            {
                if (Math.Abs(AbsenceRate) <= 0)
                {
                    return "0";
                }
                else
                {
                    return (AbsenceRate * 100).ToString("f2") + "%";
                }
            }
        }

        [Nest.Date(Name = "CreateTime", Format = "yyyy-MM-dd'T'HH:mm:ss.SSS'+'Z||yyyy-MM-dd'T'HH:mm:ss||strict_date_optional_time", IgnoreMalformed = true)]
        public DateTime CreateTime { get; set; }
    }
}
